A new multimedia cryptosystem using chaos, quaternion theory and modular arithmetic

Based on the combination of quaternion numbers, residual matrices, and chaotic attractors, a new cryptosystem is proposed for multimedia processing files such as images and audio. The key employed in this encryption schema consists of an image with a wide and sensitive range, obtained from the Julia Quaternion set rendered using a computational tool. Due to the use of quaternion matrices mixing the information between RGB layers and audio samples was possible, whereas using XOR operation and residual matrices modulus 257, added high sensitivity to small perturbations during encryption, key preparation and decryption processes, to such an extent that a minimal change in the image or in the audio leads to a totally different encryption result. The use of dynamic programming also reduced the processing time for matrix operations on the \documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$\mathbb {Z}_{257}$\end{document}ℤ257 ring. To corroborate security of the algorithm, different tests were performed, including the National Institute of Standards and Technology test obtaining different indicators that were compared with other scientific references of similar works, finding behavioral patterns in accordance with those referenced works.


Introduction
During recent times consumption of multimedia on Internet has increased drastically, COVID-19 pandemic has also contributed in this sense, reason why the scientific community continues developing mathematical and engineering strategies that lead to cryptographic solutions each time more secure and efficient. In the current work, quaternions, chaotic attractors and modular arithmetic are employed in order to design a cryptographic scheme focused on multimedia files (audio and images).

Multimedia and traditional schemes
The increase in information volume exchange through public channels has raised the need to protect data confidentiality. The ever-increasing flux of multimedia files on the Internet has been reported by FileCatalyst (a firm responsible for providing software services to speed up and optimize the transmission of multimedia files), showing the range of sizes for different types of multimedia files in 2020. This data is consolidated in Table 1. The table illustrates an exponential increase in file size regarding new technologies, and this trend is expected to continue with the arrival of new developments such as 8K and augmented reality.
The Canadian company Sandvine, specialized in providing solutions for network policies and control of landline and mobile communications services, with emphasis on cyber security, in its annual report, shows that multimedia consumption all over the world had reached almost 45% in 2018 and 60% in 2020, so therefore it is necessary to strengthen encryption schemes for multimedia files by providing academic solutions that are applicable to the industry [10].
Growing concern for the protection of information led to traditional encryption schemes such as Advanced Encryption Standard (AES) and Data Encryption Standard (DES) emerged, however, due to limitations such as the handling of high-volume information, low levels of entropy and the high correlation of data, these traditional algorithms are less suitable for multimedia encryption [14,27]. The performance of AES leads to redundancy when applied to large files, which has prompted the proposal of new specialized approaches for multimedia files such as those based on elliptical curves [6,40], chaotic attractors, quantum computing, DNA code [38,51,53], commutative and non-commutative rings, cellular automatons [5] and Visual Cryptography-Based Watermarking [36].

Quaternions and cryptography
Quaternion numbers have a non-commutative ring structure, which makes them useful in cryptography and image processing, since RGB channels are handled jointly by each quaternion component and rotations require less computational processing compared to their vectorial counterpart.
These numbers have been use in the last decade as a language in a variety of cryptography applications such as security schemes for multimedia files, key generation, public key algorithms, digital signatures, and hashing. Some related works are described below.
In [9,17], an image, audio and text encryption model is proposed using Quaternion Fourier Transform (DQFT). Regarding key generation proposals, the work in [4] uses Julia-Quaternion set to generate keys in real time. Other studies, such as [15,41], and [20], use Quaternion polynomials, modular operations and powers of Quaternion numbers to produce different public key algorithms. In [48] and [30], hashing and security schemes over a Wifi network are designed taking advantage of Quaternion rotations. Other works that utilize quaternions for handling pixel rotations in images can be found in [8,12,14,49,52].
A meaningful work in the medical sector was proposed in [13], the authors intended to achieve a balance between security level and performance of a cryptographic algorithm suitable for handling large volumes of medical information. In order to achieve this, they relied on quaternion theory and modular arithmetics, proposing a model focused on the secure handling of digital images and communication for DICOM medicine, in this case, taking advantage of quaternion rotation mechanism (which requires minimal computational cost) defining a Feistel-type encryption process on which for each iteration a different quaternion encryption key was used.
However, authors subsequently identified a weaknesses in their original proposal, that led them to design an encryption model with similar characteristics at [12] trying to address the vulnerabilities found in their previous work. Essentially, they define a new mechanism for key generation given the Julia quaternión set, preserving the rotation scheme and the Feistel-type encryption process used in their original algorithm.

Chaos and cryptography
Moreover, chaos properties are very useful in cryptographic systems because its applications comprehend from key generation and system synchronization schemas to pseudo-random number generation algorithms.
There are also works focused on application of logical operations such as XOR to provide new security layers based on pseudo-random number generators (PRNG); such is the case of [37], in which the XOR operation is used between the adjacent pixels of a gray-scale image, leading to an increase in security of the scheme. Likewise, in [34], three pseudo-random number generation algorithms, using XOR and AND logic gates, cleared successfully all the security tests associated to the NIST sts-2.1.1 standard (a standard by the National Institute of Standards and Technology).
In [35], a Lorentz attractor is used to encrypt images in gray scale, on the other hand similar works like [14,44] use the same attractor adding one more dimension in order to increase the complexity and encrypt color pictures. Authors such as Min, Zhang, and Zhang [28] also proposed a pseudo-random number generator (PRNG) that complied with the metrics defined by the Federal Information Processing Standard 140-2 (FIPS) based on two chaotic attractors of three and six dimensions.
Likewise in [50], they use Rossler and Lorentz attractors in order to establish an image permutation and diffusion scheme by applying a zigzag and spiral scanning technique to pixels from original image and encrypting them using ElGamal algorithm. As a result of this approach, they reported security and performance indicators enclosed to similar encryption approaches.
In this direction, proposals presented by [18] and [27] on which they take advantage of two dimensional fractal properties like Mandelbrot's and Julia's set, are clear evidence that it is possible to propose new chaos based cryptosystems with security measures closer to those of traditional schemes.
For example, works proposed in [2, 21, 23-25, 31, 33, 39, 46, 47, 55, 56] focus on the algorithm design for image encryption using different chaotic attractors of one or more dimensions, security and performance results demonstrate them to be security effective in different fields.
Moreover, although in [26,29,32] they develop chaos based algorithms for image encryption, they deserve to be noticed because of the use of DNA encryption, on which they achieve convincing results in cryptography.

Modular arithmetic and cryptography
Another interesting concept that has been applied in cryptography and science is the use of residual classes, leading among other things to formalization of residual matrix theory, such concept originated with the proposal of Rabin's asymmetric cryptosystem, and has evolved thanks to the introduction of the latest generation of computers. At [16] they suggest the use of residual classes to propose a modification of Rabin's asymmetric model applied to text message encryption, achieving an increase in blocks size used by the original model. Moreover, they consolidate three algorithms which through hardware implementation shows that runtime is reduced by approximately half in comparison with the original Rabin's method, thanks to a more efficient way to calculate modular powers and roots.

About this approach
Based on related works as well as on approaches found in [4,[14][15][16][17], this paper proposes the use of Quaternion theory with residual matrices in order to design a new cryptosystem intended for multimedia files. The cryptosystem uses a chaotic dynamic system to obtain an image that serves as a private key. Parameters for private key generation are forwarded through a public key algorithm. The cryptosystem involves several layers of protection including modular arithmetic, XOR operation and quaternion product.
An advantage of this paper lies in the use of a quaternion matrix to perform simultaneous operations between RGB layers and audio samples which are handled through the quaternion real component, decreasing the processing of diffusion and permutation operations as they are performed using parallel computing.
When images are generated from chaotic systems with 3 or more dimensions, a huge number of possibilities are added to guarantee the uniqueness of each image, such as its initial conditions (sensitivity), cutting planes, iterations (periodicity), texture material of the chaotic system, colors, patterns, objects in space, their physical properties (shape, reflection rates, patterns, colors) and how they interact, all of these guarantee a large and secure key space.
If an equally unique sequence of pseudo-random numbers can be created from each unique rendered image that is sensitive to even the smallest bit change, then it will serve as a key in a cryptosystem. In this proposal, the key image is obtained from Julia's quaternion set whereby its dynamic nature constitutes an advantage in key's security.
On the other hand, modular inverse 257 is employed because adding the unity to all RGB values in each component results in a range between [1,256], thus guaranteeing the uniqueness of modular inverse, this fact is exploited in order to increase pixel's sensitivity and ensure that the slightest change in key image generates a different bit-stream. Additionally, the algorithm is designed in such way that every key's pixel is relevant to the whole encryption process.
In order to safely manipulate multimedia information of this proposal, the encryption mechanism handles quaternion matrix multiplication with integer entries, and also relies in modulus 257 residual classes calculations through parallel processing and dynamic programming, simplifying the computational cost which is an advantage related to computational complexity.
The necessary concepts are explained in Section 2, followed by the proposed model in Section 3, after this, implementation is shown in Section 4, followed by the different test and complexity analysis in Section 5, and finally conclusions are drawn in Section 6.

Preliminaries
The cryptosystem proposed in this paper involves two main components, encryption algorithm and key generation. The theoretical basis for the proposed algorithm is described below.

Quaternion numbers
The Quaternion number set H is defined by three imaginary units i, j, k; a Quaternion q has a form as shown in (1): where v is vector v = (b, c, d); a and v are named real and vectorial part of Quaternion respectively. If the real part of Quaternion is zero, the resulting number is known as a pure Quaternion.
On Quaternion set H , addition and multiplication operations are defined and fulfill the structure of a non-commutative division ring (the cryptosystem proposal takes advantage of this) [19].

Residual matrices
The notion of congruence was given by Gauss and dates back to 1801. Specifically, given x, y, m positive integers, x is congruent with y module m (represented by (2)) if m divides the number x − y.
x ≡ y mod m This notion satisfies the properties of an equivalence relation, which eases the grouping of integers in disjunct families given the fact that two positive integers are congruent module m if and only if they are in the same family, they are known as residual classes module m, and they are designated by Z m . It should be noted that there are exactly m residual classes module m, and that Z m has a commutative ring structure given the sum and product defined for them [18].
Residual classes have also brought up the need to solve congruential equations from the simplest ones like those of linear and quadratic type, to simultaneous congruence systems. This is where the Chinese Theorem of the remainder proposed by mathematician Sun Tzu comes into place as a powerful tool to find solutions for linear congruence systems which is also applied for solving polynomial congruencies for composite modules.
Theory of residual classes has been widely applied into cryptography mainly to reduce the number of operations through congruencies when dealing with excessively long values, as a consequence it results into a decrease of computational speed, making room for cryptographic model proposals based on them and the notion of residual and inverse matrices.

Chaotic dynamical systems
The chaotic dynamical system definition adopted in this document was proposed in 1948 by Robert Devaney [11]. Chaos is an aperiodic behavior sensitive to initial conditions found in systems as they evolve in time. This definition corresponds to the existence of a strange attractor, as explained in dynamical systems literature. The chaotic behavior of such systems is an advantage in order to propose key generation schemes using Quaternions. Such proposal is possible due to the similarity between chaotic dynamical systems properties and permutation/diffusion features for cryptographic systems.
An example of a chaotic system can be seen by iterating the quadratic function f (z) = z 2 + c over the Quaternion set, which results into the Julia Quaternion set (in honor of mathematician Gaston Julia), where c is an arbitrary parameter. Figure 1 shows a few of many fractals that can be generated from this chaotic attractor, which can also be enriched with effects typically found in a three-dimensional space such as illumination, shadows, reflections and transparencies.

Proposed model
This paper proposes an encryption system for the processing of multimedia files based on Quaternion numbers set, Julia Quaternion chaotic attractor, and residual matrices. Figure 2 gives an overview of the cryptosystem. In order to generate the cryptosystem's key as an image, a software known as PovRay was used, in which several parameters are transmitted through an insecure channel using a public key algorithm. Additionally, a cryptographically secure pseudo-random number generator (CSPRNG) should be also implemented in order to increase the security level.

Key generation
The key generated was obtained from Julia Quaternion set on which a 4-dimensional fractal is yield and intercepted by a cutting plane in order to retrieve a R 3 fractal that results in the key for encryption/decryption. Thanks to PovRay, an open source software, the key was easily generated because it provides users with a native Julia Quaternion set implementation. As another interesting feature of the software it also allows parameters adjustments such a c in f (z) function, number of iterations, the cutting plane, the camera location, as well as visual parameters like lighting, rendering texture, image background, among others.
In this paper, function f (z) = z 2 + c was used with c and z both being Quaternions. The cutting plane is denoted as pc and the number of iterations corresponds to n. Four RGB   15, 0.20, 0.8), 512 × 512, F r = 8. Source: Own elaboration with PovRay vectors were used for color depth. The radial frequency is denoted as F r and the size of the multimedia object to be encrypted is specified in all cases. An example of a key obtained from PovRay is shown in Fig. 3.

Key distribution
In this paper, the cryptosystem implemented 9 independent sub-keys in order to send all the necessary key parameters. Each parameter uses a different key denoted by k i , where i refers to the required key generation parameters to be sent.
The parameters in question are as follows: Julia fractal generator constant c; cutting plane pc; random generated Quaternions that are associated to the RGB color percentage for background texture RGB 1 , RGB 2 , RGB 3 and RGB 4 ; Quaternion p, which is the combination of the radial frequency F r , number of iterations, n and two M, N values corresponding to the image height and width; Quaternion t which is composed from the audio sample, frequency as for framerates and snake algorithm displacement snk; and finally a Quaternion s, which corresponds to the CSPRNG seed. The key is then obtained from (3) to (11).
In order to avoid the discrete logarithm problem, various public key proposals have been introduced using Quaternions for key parameters distribution [15,20,41].

Encryption model
The encryption process is four-fold: -Key preparation.
-Residuals matrix multiplication -Quaternion Product Calculation -Inverse residual matrix multiplication Figure 4 illustrates the encryption process.

Key preparation
With the aim of ensuring the best entropy and sensitivity to small changes, the following steps were included in order to prepare the key for encryption process: 1. Julia quaternion fractal key image is rendered from parameters identified in (3) to (9), which must be sent to the receiver to retrieve the original information.

Decompose the key image into its RGB components
where r c 0ij , g c 0ij , b c 0ij are the pixels values ij with i = 1, ..., n j = 1, ..., m at layers R, G, B, respectively. 3. Add matrix Q c 0 to a pure quaternion matrix A having all of its entries equal to one in order to suppress possible zero values that may exist and interfere with the modular operation of next step thus obtaining

Define matrix D = (d ij )
which is obtained by applying operation mod 257 to the product of each component in Q c1 at ij position, in other words d ij = (r c ij g c ij b c ij ) mod 257. (12). 6. In case that (||Q c2 ||) mod 257 = 0 as a consequence of adding the value d ij , zeros are removed from matrix Q c2 , applying function at (13) element by element obtaining

Calculate the (mod 257) modular inverses for each RGB layer entries present in matrix
In summary, the proposed algorithm key is given by quaternion matrix Q c3 .

Quaternion matrix generation
Depending on multimedia type, one of the following processes is carried out: , in this case a = 0, subsequently the original image matrix is masked by a quaterion matrix with random integer entries Q m obtained from a CSPRNG instantiated by seed s specified at (10), this results in matrix Q 1 = (Q i +Q m ) mod 256 = (q 1 ij ), which is then arranged in quaternion vectors Q 2 = (q 2 1j ) in R nm for j = 1, 2, ..., mn. In order to increase the cryptosystem's small changes sensitivity, an algorithm is applied on Q 2 obtaining matrix Q 3 = snake(Q 2 ), which consists in the XOR operation application between vector's adjacent quaternions, starting from snk vector position according to (11), but moving between the quaternion's cartesian coordinates as shown in Fig. 5, a point to note is that arrows point out the trajectory orientation to be followed. In particular, along the brown trajectory, the sequence of operations performed is shown at (14). Hence, result from previous XOR operation is then stored in the major index for further use at next iteration. On (15) the red trajectory sequence is presented at Fig. 5 which traverses from right to left, for this case, XOR operation result is stored in the minor index determined by trajectory direction.
It is possible to generalize the XOR operation carried out along the four trajectories according to expressions shown at (16).

Left to right Right to left
-For audio: Given as value present at (11), the 32-bit samples are decomposed (it is also possible to adjust the audio for 64-bit samples) into 4 8-bits inputs and then stored in the quaternion real part a of Q i = a + Ri + Gj + Bk = (a ij + r ij i + g ij j + b ij k).
If there is only an audio sample to be processed, an arbitrary white noise image is used in order to implement the same mask and snake process carried out for images. -For video: A combination of the previous cases is applied. However, to ensure synchronization, audio component is divided into small samples according to the number of frames per second.
Up to this step multimedia information has been hidden in quaternion matrix Q 3 .

Residual matrix multiplication
Using matrix Q 3 and two invertible residual square matrices M, N with m and n sizes respectively in Z 257 , the matrix multiplication described at (17) is applied.
The main purpose for calculations to happen in Z 257 space is to reduce computational time and guarantee uniqueness of the inverse residual matrix, which is achieved by determinant d mod 257 being different than zero.

Quaternion product calculation
A modular operation is applied to the quaternion product between key p c ij given by (13), its modular inverse p −1 c ij and quaternion q 4ij present at (18).
Taking advantage of quaternion numbers algebra, we generate matrix Q 5 which is used at next item in order to add a security layer.

Inverse residual matrix multiplication
To end up the encryption process, residual matrices of item Section 3.3.3 are re-used but this time applying their residual inverses along with Matrix Q 5 , thus obtaining Q e given by  (19), which at the end is an array containing all original encrypted information and that is transmitted over the network in a secure way.

Decryption model
Based on matrix Q e , the decryption mechanism is similar to its encryption counterpart in reversed order, until matrix Q i is obtained, which is shown in Fig. 6.

Implementation
Several tests were performed using the Lena picture and six different images from the USC-SIPI Image Database, as for the audio sample, Beethoven's Moonlight Sonata musical composition from Ludwig van Beethoven was taken into consideration, finally the key presented in Fig. 3 was chosen for encryption/decryption. Images (a), (b), (c),(d), (e), (f) and (g) along with audio sample (h) are shown in Fig. 7. The implementation was performed using MATLAB Total Academic Headcount (TAH) license, and a computer whose specifications were: AMD Ryzen 1600x 3.6Ghz-3.9Ghz, Nvidia 2060 and 24 GB RAM at 3000 mHz. Following the proposed scheme, at first the key image preparation is performed, thus obtaining image at Fig. 8, afterwards, the encryption algorithm steps are executed sequentially on all layers. In order to show a particular application case, the Lena's ( Fig. 7(b)) green layer transformation over the encryption process is presented at Fig. 9, showing that under this approach the original information is hidden.
The final encryption results for the 7 sample images and audio sample correspond to the Q e matrices and can be observed in Fig. 10. A point to note is that the encrypted audio sample varies according to the image employed in the process.
In order to recover the original information, elements from Fig. 10 are taken along with the prepared key from Fig. 8 and steps specified on Fig. 6 are executed, thus obtaining the original information shown at Fig. 11.

Security analysis
The analysis applied to the proposed cryptosystem satisfies the National Institute of Standards and Technology (NIST) [7] specifications, which also considers histograms, correlation coefficients, differential analysis, key sensitivity and entropy values. The tests were performed using the images and audio sample presented in Fig. 7 and key shown at Fig. 8.

NIST statistical test
This test consists of 15 different statistical measures that evaluate the chaotic bit-stream sequence on a statistical level, P-values establish whether a sequence pass the tests Fig. 11 Algorithm items after decryption process. Source: Own elaboration using MATLAB successfully or not, for this, such value must be greater than 0.01 at each one of the tests applied on m blocks out of n bits [7].
NIST tests on this work were performed with the "sts-2 1 2" Suite, by using as input file four-component data blocks corresponding to each quaternion matrix entry specified at (19), the library assessed 80 blocks out of 10 5 bits, results presented at Table 2 are enough to state that the cryptosystem is statistically secure [14].

Histogram analysis and χ 2 test
Distribution frequency histograms were plotted for each one of the RGB layers and audio channel in Fig. 7. Histograms in Figs. 12, 13, 14 and 15, show that encrypted information tends to be uniformly distributed, which is a good indicator for the encryption scheme. Also note, that audio sample histograms show different results based on the encrypted image.
On the other hand, χ 2 test was used in order to establish the pixels distribution uniformity in encrypted image, a small value of this indicator means high pixel uniformity, which is desirable into a cryptographic process. The expression for this test is given by (20):  Table 3 summarizes χ 2 values for original and encrypted images as well as some reference comparisons, the values obtained shows lower values for encrypted images and within the reference's range.

Correlation analysis
Correlation analysis is a statistical measure that evaluates diffusion and confusion for an encryption algorithm [54]. Such analysis is based on (21).  (22), (23) and (24), respectively.
In equations above, x i corresponds to i-th sample's value, y i is the adjacent value and E(x) is the mean given by (25).
Correlation coefficients for encrypted images were obtained from around 10% random samples of total's data in horizontal, vertical and diagonal directions. Each sample is obtained from the corresponding pixel associated to each layer, Table 4 shows results for encrypted images and some references taken into consideration.
Note that results present at Table 4 resemble those reported in other works with similar approaches as shown in Table 5.
For audio sample in Fig. 7(d), correlation analysis was done by comparing the left and right channels of original and encrypted samples. Correlation was also computed by comparing the original and encrypted version of each channel independently. The original audio Table 4 Correlation coefficients for images in Fig. 7(a)  correlation on both channels was found to be 0.2342 whereas encrypted samples test results are shown in Table 6, 'L' and 'R' represent the left and right channels respectively, 'o' refers to the original audio and 'c' denotes the ciphered audio. According to Tables 4 and 6 results, it can be concluded that original images and audio sample presented a strong correlation (close to 1), whereas the correlation coefficients for the encrypted information were close to 0, values that are very similar to those presented at Table 5. Table 6 Correlation coefficients for audio sample of Fig. 7

Differential analysis
Differential analysis in multimedia files is measured by introducing small changes into the original information. For images case, one pixel value is modified randomly, whereas for an audio file a random sample is chosen and the least significant bit is changed by inverting its binary value, resulting into a new audio signal [22]. Once a small change is introduced, both the original and altered multimedia information are encrypted using the same key for comparison. Given that purpose, metrics such as Number of Pixels Change Rate (NPCR), Unified Average Changing Intensity (UACI) and Number of Sample Change Rate (NSCR) were computed for each RGB layer and audio channel. Expressions for these metrics are defined from (26) to (31).
Where C 1 (i, j ), C 2 (i, j ) are two encrypted images, the first one corresponds to original image and the second one to the same image with one altered pixel; M and N correspond to image's size.
Where A and A are two encrypted audio signals, first one being the original sample and the other one the audio with one altered bit; L corresponds to audio vector length.
Values obtained in this paper are similar to those of other references presented in Table 7. These results shows that with a minimum variation in original information, different encrypted information is obtained, translating into a high resistance to differential attacks.

Encryption quality analysis
This type of analysis measures the difference between repetition frequency for each pixel value of plaintext and encrypted image, expression given in (32) describes encryption measure quality (EQ), where o i (P ) and o i (C) correspond to the number of pixel with i intensity in original and encrypted images respectively.  Table 9 shows encryption quality analysis results obtained from the proposed algorithm, which complies with expression (33) and even shows superior measures than those reported in [43].

Key sensitivity
In order to evaluate the key sensitivity in proposed cryptosystem, elements used in Fig. 7(b) and (d) were encrypted with Fig. 8 key. Subsequently, small changes were introduced to arbitrary key parameters such as the RGB 1 vector and constant c of f (z) function. In both scenarios using such non-significant variations, decryption of original information was unsuccessful. Results obtained are shown in Figs. 16 and 17, indicating that proposed cryptosystem is sensitive to small key changes with an approximate precision of 10 −11 ≈ 2 −33 , result being useful for key space calculation in next section.
As it can be seen on results obtained, knowing even one of the parameters isn't enough to decipher the original multimedia file, therefore it is possible to assure that the proposed system is resistant to brute-force attacks. In addition to that, a small variation in any of key parameters, causes totally different results. This was experimentally corroborated by calculating the correlation between two key images with insignificant changes in their parameters, obtaining an average correlation of 0.0153, which implies that even if the algorithm is known, but there is no certainty about all parameters used in the encryption process, it is impossible to recover the original information.

Key space analysis
According to the proposal, system's key space can be deduced from CSPRNG seed, snk shift and the different parameters involved in key generation such as c, pc (128 bit quaternions given by Section 5.6); RGB 1 , RGB 2 , RGB 3 , RGB 4 8 bits vectors for each input in R 3 ; and n, F r integers in the order of 5 and 3 bits respectively, indicating that proposed algorithm key space is larger than 2 360 = 2 2 * 128+12 * 8+5+3 .

Entropy analysis
An entropy value means the level of resistance to statistical attacks as well as the randomness level of encrypted information, this value is calculated using (34), where M is the maximum information value to be analyzed, m i is the i-th information's value and p(m i ) the m i probability of occurrence [3]. In the case of RGB images, with 256 possible values for each layer, encrypted image entropy must be close to 8, which also applies for audio samples, this kind of analysis indicates a high resistance to this kind of attack [22,54].
Values obtained in this proposal for image layers and audio channels are close to 8, showing that ciphered information has a high confusion level and are very similar to results found on different references, indicating a high disorder degree. Results are presented in Table 10.

Local entropy analysis
Sometimes Shannon entropy is not a reliable indicator of randomness level, for this reason it is necessary to calculate different local entropies that reflect a more accurate randomness level of pixels [45].
H (m l ) is given by (34). Table 11 presents local entropy values obtained for RGB layers in each image showing that results are close to 8, and also within the range from other references.

Robustness analysis
Salt & pepper and occlusion tests were performed on proposed algorithm demonstrating a high sensitivity towards any disturbance on encrypted information, due to the fact that by altering a single bit and having all the necessary parameters to start the decryption process it was not possible to recover the original file as shown in Fig. 18. For example the robustness for an image of 512 × 512 size, when a single bit change is done corresponds to 1 32×512×512 = 1.192 × 10 −7 bits where factor 32 is associated to the three RGB layers and audio channels altogether using 8 bits precision each, such fact is perceived as a strength for the proposed encryption method, however, this entails that a mechanism must be implemented in order to fix errors inherent to the communication channel, guarantying full reliability and ensure that receiver can access the multimedia file sent, an analysis with similar results is presented in [56].
Peak signal-to-noise ratio (PSNR) is a measure that indicates the noise that can be added in a decryption process, a larger value in this indicator evidences a lower noise proportion in the recovered information. Equation 36 defines PSNR, in the case of this proposal, the mean square error (MSE) is zero, because the two images are identical, therefore PSNR has a tendency to infinity, indicating that during the decryption process there are no alterations in original information.
Also Figs. 19 and 20 show that for black or white images along with audio sample from Fig. 7(d), encryption process can be performed successfully.

Resistance attack analysis
Four common cipher attack types are Ciphertext-Only, known-plaintext, chosen-ciphertext and chosen-plaintext, with chosen-plaintext being the most effective one. According to [14], a system resistant to this type of attack is resistant to the others, regardless of plaintext. Information is masked using a CSPRNG to avoid frequency attacks, followed by the snake, which has high sensitivity since a small change in the masked image causes alterations in all layers, these two operations are linear, while the matrix and quaternion product are not. In case of a possible plaintext attack it is necessary to carry out the inversible matrix search, which implies a high amount of computational resources.
Furthermore, proposed algorithm also features brute force attack resistance because key is an image generated from 360 bits according to Section 5.7 and include other security layers such as the snake shift NM, residual matrix product 2 8N 2 2 8M 2 and the CSPRNG seed at least of 2 128 bits.

Computational complexity
Computational complexity of an algorithm refers to the time measurement an algorithm execution takes with respect to data size, which is an indicator of the algorithm's efficiency and represents its computational boundary. In this article using the computer described in Section 4, and Lena image with different resolutions (128 × 128, 256 × 256, 512 × 512), the time taken by algorithm respectively is presented in Fig. 21 and Table 12, highlighting that this proposal has a quadratic complexity O(n 2 ), nevertheless as information increases, time increases proportionally to matrix size.

Conclusions
An encryption method applied to multimedia files was proposed based on the properties of chaotic attractors in a 3D space, using an image generated from the Julia Quatertion attractor as a key ensuring with this a wide space and sensibility.
Quaternion numbers were used to take cryptographic advantage of various properties such as the non-commutative product, which avoids typical issues with traditional encryption schemes such as the discrete logarithm problem and faster calculation for rotation operations. Also using this set of numbers made it possible to design an integrated structure for audio and images, ensuring that a variation in any part of the process produces changes in the whole information. Using the congruence theory properties and modulus 257 residual matrices, it was achieved that small changes in pixels generate totally different keys increasing its sensibility. In addition, the use of residual matrices made it possible to take advantage of their inverse and non-commutational product, making it easier to include the modified information within the Z 257 ring.
Combination of quaternions and residual matrices in this proposal contributed, firstly, by adding a highly sensitive, fast and nonlinear layer, which led to find safety and performance indicators comparable with similar works, this allows application of the proposed method in real world environments. On the other hand, computation time was reduced by the usage of dynamic programming and existence of an unique inverse element in Z 257 ring.
Aiming at improving results of this proposal, future work should explore the use of other security layers, chaotic images and attractors along with its behavior on 3D environments in order to improve the algorithm and its security, especially as it related to salt & pepper and occlusion tests. In the same way the proposed algorithm could be implemented using parallel programming reducing its computational requirements.
Funding Open Access funding provided by Colombia Consortium.

Data Availability
The datasets analysed during the current study are available in the USC-SIPI Image repository following the link https://sipi.usc.edu/database/.
For key generation PovRay was used, a Free software with a native Julia Quaterion Fractal implementation, for more information go to https://www.povray.org/documentation/view/3.7.0/280/.
The authors declare that data supporting findings of this study are available within the article. Also, data is available from authors upon reasonable request.

Declarations
Consent for Publication All authors have given their consent for publication.

Conflict of Interests
The authors declare that they have no conflict of interest.
Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.